﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace LambdaTest
{
    public class Lambdas
    {

        public void Start()
        {
            var stringsToExamine = new List<string> { "kalle", "pelle", "lisa", "rosa" };
            var regexPtn = @"^.*" + @"s" + @".*$";

            var result = AnyOfPatternsIsFoundInAnyOfTheseStringsToExamine(stringsToExamine, regexPtn);
        }

        

        private List<string> TheseStringsHoldsThePattern(List<string> stringsToExamine, string regexPtn)
        {
            var reg = new System.Text.RegularExpressions.Regex(regexPtn);
            var result = new List<string>();
            foreach (var str in stringsToExamine)
            {
                if (reg.IsMatch(str)) result.Add(str);
            }
            return result;
        }

        private bool PatternIsFoundInAnyOfTheseStrings(List<string> stringsToExamine, string regexPtn)
        {
            var reg = new System.Text.RegularExpressions.Regex(regexPtn);

            //does any condition satisfy the condition?
            var conditionSatisfied = stringsToExamine.Any(str => reg.IsMatch(str));
            return conditionSatisfied;
        }

        private bool AnyOfPatternsIsFoundInAnyOfTheseStringsToExamine(List<string> stringsToExamine, List<string> regPtns)
        {
            var anyOfPatternsIsFoundInAnyOfTheseStringsToExamine =
                regPtns.Any(currentPtn => PatternIsFoundInAnyOfTheseStrings(stringsToExamine, currentPtn));

            return anyOfPatternsIsFoundInAnyOfTheseStringsToExamine;
        }


    }
}
